package thread;

import java.util.Scanner;

public class demo9 {
    public static void main(String[] args) {


        Thread t = new Thread(()->{
            Thread cur = Thread.currentThread();
            while(!cur.isInterrupted()) {
                System.out.println("aaa");
                try {
                    Thread.sleep(1000);//由于sleep又会把interupt给设置为false,所以这里会持续的进行,不会中断
                } catch (InterruptedException e) {
                    e.printStackTrace();

                }
            }
        });
        t.start();
        System.out.println("输入0 结束进程t, 输入1继续进程t");
        Scanner in = new Scanner(System.in);
        int tmp = in.nextInt();
        if(tmp == 0) {
            t.interrupt();
        }


    }


}
